﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using dhsystem.Main;
using dhSystemBLL.produceBLL;
using baseSet.importExport;
using dhDataAcess.baseBLL;

namespace dhsystem.produceForm.Stock
{
    public partial class FrmmaterialStockList : Form
    {

        materialStockListBLL materialStockList = new materialStockListBLL();
        string type;
        public FrmmaterialStockList(string _type)
        {
            type = _type;
            InitializeComponent();
        }
        //打开窗口时显示列表数据
        private void FrmmaterialStockList_Load(object sender, EventArgs e)
        {
            //bindingSourcematerialStockList.DataSource = materialStockList.getmaterialStockListAll();
            //dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
            //DcolumnSet.colSet(moduleInfo.materialStockList, dGridmaterialStockList);
            //toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
            if (type == "原材料")
            {
                bindingSourcematerialStockList.DataSource = materialStockList.getV_materialStockListBymtypeNoAll ();
                dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
                DcolumnSet.colSet(moduleInfo.V_materialStockList, dGridmaterialStockList);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
            }
            else
            {
                this.Text = "五金库存表";
                bindingSourcematerialStockList.DataSource = materialStockList.getV_materialStockListBymtypeAll ();
                dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
                DcolumnSet.colSet(moduleInfo.V_materialStockList, dGridmaterialStockList);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
            }
        }
        //工具栏查询按钮，查询所有列表数据
        private void toolQuery_Click(object sender, EventArgs e)
        {
            FrmDataQuery query = new FrmDataQuery(moduleInfo.V_materialStockList );
            DialogResult result = query.ShowDialog();
            if (result == DialogResult.Yes)
            {
                dGridmaterialStockList.DataSource = query.rTable;
            }
        }
        //查询按钮，按条件查询数据
        private void buttonQuery_Click(object sender, EventArgs e)
        {
            if (type == "原材料")
            {
                bindingSourcematerialStockList.DataSource = basicSql.getV_materialStockList("%" + textorderDetailNoQuery.Text + "%");
                dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
                DcolumnSet.colSet(moduleInfo.V_materialStockList, dGridmaterialStockList);
            }
            else
            {
                bindingSourcematerialStockList.DataSource = basicSql.getV_materialStockListwj("%" + textorderDetailNoQuery.Text + "%");
                dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
                DcolumnSet.colSet(moduleInfo.V_materialStockList, dGridmaterialStockList);
            }
        }
        //刷新按钮
        private void buttupdate_Click(object sender, EventArgs e)
        {
            if (type == "原材料")
            {
                bindingSourcematerialStockList.DataSource = materialStockList.getV_materialStockListBymtypeNoAll();
                dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
                DcolumnSet.colSet(moduleInfo.V_materialStockList, dGridmaterialStockList);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
            }
            else
            {
                this.Text = "五金库存表";
                bindingSourcematerialStockList.DataSource = materialStockList.getV_materialStockListBymtypeAll();
                dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
                DcolumnSet.colSet(moduleInfo.V_materialStockList, dGridmaterialStockList);
                toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
            }


            //bindingSourcematerialStockList.DataSource = materialStockList.getmaterialStockListAll();
            //dGridmaterialStockList.DataSource = bindingSourcematerialStockList;
            //DcolumnSet.colSet(moduleInfo.materialStockList, dGridmaterialStockList);
            //toolStripStatusLabel1.Text = "数据总条数:" + dGridmaterialStockList.RowCount.ToString() + "条";
        }
        //工具栏退出按钮，退出窗口
        private void toolExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //datagridview第一列显示行号
        private void dGridstockDate_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            e.Row.HeaderCell.Value = string.Format("{0}", e.Row.Index + 1);
        }

        private void toolExport_Click(object sender, EventArgs e)
        {
            FrmExcelExport frm = new FrmExcelExport(moduleInfo.V_materialStockList  , dGridmaterialStockList , "原材料库存信息");
            frm.ShowDialog();
        }

        private void toolSet_Click(object sender, EventArgs e)
        {

        }
    }
}
